<template>
  <div class="songDetailed">
    <!-- 歌单选项开始 -->
    <div class="songOptions">
      <div class="songOptionOne">
        <div class="songTitle">
          <i class="iconfont">&#xe601;</i>
          语种
        </div>
        <ul
          class="songLanguage"
          v-for="(cat, index) in CatList"
          :key="index"
          @click="hankSongList(cat)"
        >
          <li
            class="songOptionContent"
            v-if="cat.category == 0"
            :class="songName == cat.name ? 'active' : ''"
          >
            <span>
              {{ cat.name }}
            </span>
          </li>
        </ul>
      </div>
      <div class="songOption">
        <div class="songTitle">
          <i class="iconfont">&#xe7f0;</i>
          流派
        </div>
        <ul
          class="songSect"
          v-for="(cat, index) in CatList.slice(0, 38)"
          :key="index"
          @click="hankSongList(cat)"
        >
          <li
            class="songOptionContent"
            v-if="cat.category == 1"
            :class="songName == cat.name ? 'active' : ''"
          >
            <span>{{ cat.name }}</span>
          </li>
        </ul>
        <ElPopover placement="bottom" :width="300" v-model:visible="visible">
          <template #reference>
            <ElButton class="songOptionOther" @click="visible = !visible">
              更多
              <i class="iconfont" v-if="!visible">&#xe731;</i>
              <i class="iconfont" v-else>&#xe611;</i>
            </ElButton>
          </template>
          <ul
            class="songSectOther"
            v-for="(cat, index) in CatList.slice(38)"
            :key="index"
            @click="hankSongList(cat)"
          >
            <li
              class="songOptionContentOther"
              v-if="cat.category == 1"
              :class="songName == cat.name ? 'active' : ''"
            >
              <span>{{ cat.name }}</span>
            </li>
          </ul>
        </ElPopover>
      </div>
      <div class="songOption">
        <div class="songTitle">
          <i class="iconfont">&#xe625;</i>
          主题
        </div>
        <ul
          class="songSect"
          v-for="(cat, index) in CatList.slice(0, 33)"
          :key="index"
          @click="hankSongList(cat)"
        >
          <li
            class="songOptionContent"
            v-if="cat.category == 4"
            :class="songName == cat.name ? 'active' : ''"
          >
            <span>{{ cat.name }}</span>
          </li>
        </ul>
        <ElPopover placement="bottom" :width="300" v-model:visibles="visibles">
          <template #reference>
            <ElButton
              class="songOptionOther"
              @click="visibles = !visibles"
              @blur="visibles = false"
            >
              更多
              <i class="iconfont" v-if="!visibles">&#xe731;</i>
              <i class="iconfont" v-else>&#xe611;</i>
            </ElButton>
          </template>
          <ul
            class="songSectOther"
            v-for="(cat, index) in CatList.slice(33)"
            :key="index"
            @click="hankSongList(cat)"
          >
            <li
              class="songOptionContentOther"
              v-if="cat.category == 4"
              :class="songName == cat.name ? 'active' : ''"
            >
              <span>{{ cat.name }}</span>
            </li>
          </ul>
        </ElPopover>
      </div>
      <div class="songOption">
        <div class="songTitle">
          <i class="iconfont">&#xe6f8;</i>
          情感
        </div>
        <ul
          class="songSect"
          v-for="(cat, index) in CatList.slice(0, 40)"
          :key="index"
          @click="hankSongList(cat)"
        >
          <li
            class="songOptionContent"
            v-if="cat.category == 3"
            :class="songName == cat.name ? 'active' : ''"
          >
            <span>{{ cat.name }}</span>
          </li>
        </ul>
        <ElPopover placement="bottom" :width="300" v-model:visibled="visibled">
          <template #reference>
            <ElButton
              class="songOptionOther"
              @click="visibled = !visibled"
              @blur="visibled = false"
            >
              更多
              <i class="iconfont" v-if="!visibled">&#xe731;</i>
              <i class="iconfont" v-else>&#xe611;</i>
            </ElButton>
          </template>
          <ul
            class="songSectOther"
            v-for="(cat, index) in CatList.slice(40)"
            :key="index"
            @click="hankSongList(cat)"
          >
            <li
              class="songOptionContentOther"
              v-if="cat.category == 3"
              :class="songName == cat.name ? 'active' : ''"
            >
              <span>{{ cat.name }}</span>
            </li>
          </ul>
        </ElPopover>
      </div>
      <div class="songOption">
        <div class="songTitle">
          <i class="iconfont">&#xe665;</i>
          场景
        </div>
        <ul
          class="songSect"
          v-for="(cat, index) in CatList.slice(0, 40)"
          :key="index"
          @click="hankSongList(cat)"
        >
          <li
            class="songOptionContent"
            v-if="cat.category == 2"
            :class="songName == cat.name ? 'active' : ''"
          >
            <span>{{ cat.name }}</span>
          </li>
        </ul>
        <ElPopover placement="bottom" :width="300" v-model:visibleo="visibleo">
          <template #reference>
            <ElButton
              class="songOptionOther"
              @click="visibleo = !visibleo"
              @blur="visibleo = false"
            >
              更多
              <i class="iconfont" v-if="!visibleo">&#xe731;</i>
              <i class="iconfont" v-else>&#xe611;</i>
            </ElButton>
          </template>
          <ul
            class="songSectOther"
            v-for="(cat, index) in CatList.slice(40)"
            :key="index"
            @click="hankSongList(cat)"
          >
            <li
              class="songOptionContentOther"
              v-if="cat.category == 2"
              :class="songName == cat.name ? 'active' : ''"
            >
              <span>{{ cat.name }}</span>
            </li>
          </ul>
        </ElPopover>
      </div>
    </div>
    <!-- 歌单选项结束 -->
    <div class="AllSongList">
      <h2>{{ songName ? songName : "全部歌单" }}</h2>
    </div>
    <!-- 歌单详情开始 -->

    <div class="songListContents">
      <div class="songListContent" v-for="songs in songList" :key="songs.id">
        <div class="songListImg">
          <i class="iconfont s" :class="songs.isSongShow ? 'actives' : ''">&#xe7f1;</i>
          <img
            :src="songs.coverImgUrl"
            alt=""
            @mousemove="isSongShowIn(songs)"
            @mouseout="isSongShowOut(songs)"
          />
        </div>
        <div class="songListName">{{ songs.name }}</div>
      </div>
    </div>
    <!-- 歌单详情结束 -->
    <!-- 分页器 -->
    <ElPagination
      class="songListPager"
      layout="prev, pager, next"
      page-count="25"
      pager-count="7"
      :total="260"
      :current-page="current"
      @current-change="getSongList"
    ></ElPagination>
  </div>

  <Live></Live>
</template>

<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
  name: "Songsheet",
});
</script>

<script lang="ts" setup>
import Live from "../../components/Live/index.vue";
import { onMounted, ref } from "@vue/runtime-core";
import { ElPagination, ElPopover, ElButton } from "element-plus";
import { getCatList } from "../../api/Home/Home";
import { getCatSong } from "../../api/Songsheet/Songsheet";

const CatList = ref([]);
const visible = ref(false);
const visibles = ref(false);
const visibled = ref(false);
const visibleo = ref(false);
const songList = ref([]);
const songName = ref();
//刷新
const loading = ref(false);
//当前页数
const current = ref(1);
//获取歌单分类
onMounted(async () => {
  const res = await getCatList();
  CatList.value = res.data.sub;
});
//显示图标
const isSongShowIn = (songList) => {
  songList.isSongShow = true;
};
const isSongShowOut = (songList) => {
  songList.isSongShow = false;
};
// 获取歌单
const getSongList = async (val: number) => {
  loading.value = true;
  current.value = val;
  const res = await getCatSong((current.value - 1) * 50, songName.value);
  // console.log(res);
  songName.value = "";
  songList.value = res.data.playlists;
  loading.value = false;
};
onMounted(getSongList(current.value));
//点击选项
const hankSongList = async (CatList) => {
  name = CatList.name;
  songName.value = CatList.name;
  const res = await getCatSong((current.value - 1) * 50, name);
  songList.value = res.data.playlists;
};
</script>

<style scoped>
.songDetailed {
  margin: 0 156px;
}
.songOptions {
  margin-top: 40px;
  height: 144px;
}
.songOptionOne,
.songOption {
  float: left;
}
.songOption {
  margin-left: 10px;
}
.songTitle {
  font-weight: bolder;
  height: 19px;
  margin-bottom: 5px;
}
.songLanguage {
  width: 160px;
}
.songSect {
  width: 240px;
}
.songLanguage,
.songSect {
  margin: 0;
  padding: 0;
}
.songOptionContent {
  list-style: none;
  float: left;
  margin-top: 10px;
  margin-right: 10px;
  width: 66px;
  height: 30px;
  line-height: 30px;
  padding: 0 2px;
  font-size: 13px;
  text-align: center;
  background-color: #f8f8f8;
  border-radius: 20px;
  cursor: pointer;
}
.songOptionContent.active {
  background-color: red !important;
  color: #f8f8f8;
}
.songOptionOther {
  list-style: none;
  float: left;
  margin-top: 10px;
  margin-right: 10px;
  width: 66px;
  height: 30px;
  line-height: 30px;
  padding: 0 2px;
  font-size: 13px;
  text-align: center;
  background-color: #f8f8f8;
  border-radius: 20px;
  cursor: pointer;
}
.songSectOther {
  width: 300px;
  cursor: pointer;
}
.songOptionContentOther {
  list-style: none;
  float: left;
  margin: 5px;
  width: 75px;
  height: 30px;
  line-height: 30px;
  padding: 0 2px;
  font-size: 13px;
  text-align: center;
  background-color: #f8f8f8;
  border-radius: 20px;
}
.songOptionOther:hover {
  background-color: red;
  color: white;
}
/* 图标 */
@font-face {
  font-family: "iconfont"; /* Project id 2952620 */
  src: url("//at.alicdn.com/t/font_2952620_uq5aucdd1qj.woff2?t=1638502117682")
      format("woff2"),
    url("//at.alicdn.com/t/font_2952620_uq5aucdd1qj.woff?t=1638502117682") format("woff"),
    url("//at.alicdn.com/t/font_2952620_uq5aucdd1qj.ttf?t=1638502117682")
      format("truetype");
}
.s {
  display: none;
  color: white;
  font-size: 50px;
  position: absolute;
  left: 90px;
  top: 90px;
  z-index: 999;
}
.actives {
  display: block;
}
.AllSongList {
  height: 36px;
  margin-top: 55px;
}
.AllSongList h2 {
  float: left;
  font-weight: normal;
  margin: 0;
  line-height: 36px;
}
/* 歌单列表开始 */
.songListContents {
  height: 3180px;
  margin: 0 -10px;
}
.songListContent {
  float: left;
  margin: 25px 9px;
  width: 224px;
  height: 268px;
}
.songListImg {
  position: relative;
  height: 224px;
  width: 224px;
  overflow: hidden;
}
.songListImg img {
  height: 100%;
  width: 100%;
  transition: all 1s;
}
.songListImg:hover img {
  transform: scale(1.1);
}
.songListName {
  margin-top: 18px;
}

/* 歌单列表结束 */
</style>
<style lang="less">
.songListPager {
  text-align: center !important;
  font-weight: 400 !important;
  button {
    width: 40px;
    height: 40px;
    box-sizing: border-box;
    font-size: 12px;
    text-align: center;
    i {
      width: auto !important;
      font-weight: 700;
    }
    &:hover {
      color: #e61723;
    }
  }
  .btn-prev {
    padding-left: 6px;
    padding-right: 12px;
  }
  .btn-next {
    padding-left: 12px;
    padding-right: 6px;
  }
  li {
    width: 40px;
    height: 40px;
    box-sizing: border-box;
    padding: 0 4px;
    font-size: 14px;

    line-height: 40px !important;
    text-align: center;
    &:hover {
      color: #e61723;
    }
  }
  .active {
    background-color: #e61723 !important;
    color: #fff !important;
  }
}
//表单
</style>
